package com.example.hotel.utils;



import com.example.hotel.entity.ResultModel;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;

import static com.example.hotel.utils.CommonUtils.*;


/**
 * 返回数据工具类
 */
public class ResultUtils {

    ResultModel resultModel = new ResultModel();//new实体对象

    /**
     * 查询
     */
    public ResultModel SelectResultUtils(List<?> entitylist, List<?> servicelist) {
        try {
            entitylist = servicelist;//调用业务逻辑层
            if (servicelist.size() > 0) {
                ResultShow(resultModel, CODEONE, SELECTSUCCESS, entitylist);
            } else {
                ResultShow(resultModel, CODEMINUSONE, SELECTFAIL, entitylist);
            }
        } catch (Exception e) {
            ResultShow(resultModel, CODEMINUSONE, SELECTFAIL, entitylist);
        }
        return resultModel;
    }

    /**
     * 查询2
     */
    public ResultModel SelectResultUtils(Serializable entitylist, Serializable servicelist) {
        try {
            entitylist = servicelist;//调用业务逻辑层
            if (entitylist != null) {
                ResultShow(resultModel, CODEONE, SELECTSUCCESS, entitylist);
            } else {
                ResultShow(resultModel, CODEMINUSONE, SELECTFAIL, entitylist);
            }
        } catch (Exception e) {
            ResultShow(resultModel, CODEMINUSONE, SELECTFAIL, entitylist);
        }
        return resultModel;
    }

    /**
     * 添加
     */
    public ResultModel InsertResultUtils(Serializable entity, Serializable serviceentity) {
        try {
            entity = serviceentity;//调用业务逻辑层
            if (entity != null) {
                ResultShow(resultModel, CODEONE, INSERTSUCCESS, entity);
            } else {
                ResultShow(resultModel, CODEMINUSONE, INSERTFAIL, new HashMap<>());
            }
        } catch (Exception e) {
            ResultShow(resultModel, CODEMINUSONE, INSERTFAIL, new HashMap<>());
        }
        return resultModel;
    }

    /**
     * 修改
     */
    public ResultModel UpdateResultUtils(Serializable entity, Serializable serviceentity) {
        try {
            entity = serviceentity;//调用业务逻辑层
            if (entity != null) {
                ResultShow(resultModel, CODEONE, UPDATESUCCESS, entity);
            } else {
                ResultShow(resultModel, CODEMINUSONE, UPDATEFAIL, new HashMap<>());
            }
        } catch (Exception e) {
            ResultShow(resultModel, CODEMINUSONE, UPDATEFAIL, new HashMap<>());
        }
        return resultModel;
    }


    /**
     * 删除
     */
    public ResultModel DeleteResultUtils(boolean b) {
        try {
            boolean result = b;//调用业务逻辑层
            if (result) {
                ResultShow(resultModel, CODEONE, DELETESUCCESS, new HashMap<>());
            } else {
                ResultShow(resultModel, CODEMINUSONE, DELETEFAIL, new HashMap<>());
            }
        } catch (Exception e) {
            ResultShow(resultModel, CODEMINUSONE, DELETEFAIL, new HashMap<>());
        }
        return resultModel;
    }
}
